package cn.south.campus.business.model.vo;

import cn.south.campus.business.model.entity.Address;
import cn.south.campus.common.model.vo.BaseVO;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 *
 * </p>
 *
 * @author chow
 * @since 2024/11/14 15:45
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class AddressVo extends BaseVO {
    /**
     * 用户id
     */
    private Long userId;

    /**
     * 收货人姓名
     */
    private String name;

    /**
     * 收货人电话
     */
    private String phone;

    /**
     * 楼栋
     */
    private String building;

    /**
     * 房间号
     */
    private String address;

    /**
     * 是否默认地址，0否，1是
     */
    private Integer isDefault;

    public static AddressVo convert(Address address) {
        if (address == null) {
            return null;
        }
        AddressVo addressVo = new AddressVo();
        addressVo.setId(address.getId());
        addressVo.setUserId(address.getUserId());
        addressVo.setName(address.getName());
        addressVo.setPhone(address.getPhone());
        addressVo.setBuilding(address.getBuilding());
        addressVo.setAddress(address.getAddress());
        addressVo.setIsDefault(address.getIsDefault());
        return addressVo;
    }

    public static Address convert(AddressVo addressVo) {
        if (addressVo == null) {
            return null;
        }
        Address address = new Address();
        address.setId(addressVo.getId());
        address.setUserId(addressVo.getUserId());
        address.setName(addressVo.getName());
        address.setPhone(addressVo.getPhone());
        address.setBuilding(addressVo.getBuilding());
        address.setAddress(addressVo.getAddress());
        address.setIsDefault(addressVo.getIsDefault());
        return address;
    }
}
